﻿#include <stdio.h>
#include <stdlib.h>
#include <math.h> 
#include <time.h>

int zufall(){
    return (rand()%2);          
}
    
void printRininslandSimonSimulation()
{
    srand(time(NULL));
    char Feld[80][100];
    int zaehler=0;

    //1. zeile zufaellig belegen
    for (int j=0; j<80; j++) {  
        if(zufall()==1)Feld[0][j] = ' ';
        else Feld[0][j] = 'X';                
    } 
           
    //restliche Zeilen 
    for (int i=1; i<80; i++) {    
         for (int j=0; j<100; j++) { 
             if((j>1)&&(j<99)){
                if((Feld[i-1][j-2])=='X')zaehler++;   //Fabrik 1
                if((Feld[i-1][j+2])=='X')zaehler++;   //Fabrik 2
             }
             if((j>0)||(j<100)){
                if((Feld[i-1][j-1])=='X')zaehler++;   //Fabrik 3
                if((Feld[i-1][j+1])=='X')zaehler++;   //Fabrik 4
             }
             if((Feld[i-1][j])=='X')zaehler++;        //Fabrik 5
             if((zaehler==2)||(zaehler==4))Feld[i][j] = 'X';
             else Feld[i][j] = ' ';     
             zaehler=0;
         } 
    }
    //Ausgabe
                  
      for (int i=0; i<80; i++) { 
        
         for (int j=0; j<100; j++) { 
             printf("%c" ,Feld[i][j]);   
                          
        } 
         printf("\n");  
    }
    system("\nPAUSE");	       
}
